package com.wlc.exception.demo02;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 英雄
 * @date 2021-07-08 15:57
 */
public class Hero {

    private String name;
    private double hp;

    public void attack(Hero hero) throws EnemyHeroIsDeadException {
        if (hero.hp == 0) {
            throw new EnemyHeroIsDeadException(hero.name + "这个英雄已经挂了，不需要再攻击该英雄了。。");
        }
    }

    public static void main(String[] args)  {
        Hero hero = new Hero();
        hero.name = "盖伦";
        hero.hp = 100;
        Hero hero1 = new Hero();
        hero1.name = "提莫";
        hero1.hp = 0;
        try {
            hero.attack(hero1);
        } catch (EnemyHeroIsDeadException e) {
            System.out.println("具体原因 " + e.getMessage());
        }
    }
}
